package foo;

public class IrSensorUmrechner {
	public static double irsInfinty = 13.0;

	public static double irse2cm(int irse) {
		int x = irse;
		double y = 0.0;
		
		if ((x>=40) && (x<288)) y = 0.002*(x-40) + 2;
		else if ((x>=288) && (x<466)) y = 0.002*(x-288) + 2.5;
		else if ((x>=466) && (x<630)) y = 0.0044*(x-466) + 3;
		else if ((x>=630) && (x<740)) y = 0.0074*(x-630) + 4;
		else if ((x>=740) && (x<810)) y = 0.0117*(x-740) + 5;
		else if ((x>=810) && (x<856)) y = 0.017*(x-810) + 6;
		else if ((x>=856) && (x<889)) y = 0.0002*(x-856)*(x-856) + 0.0292*(x-856) + 7;
		else if ((x>=889) && (x<917)) y = -0.0003*(x-889)*(x-889) + 0.0252*(x-889) + 8;
		else if ((x>=917) && (x<930)) y = -0.0001*(x-917)*(x-917)*(x-917) + 0.0018*(x-917)*(x-917) + 0.0662*(x-917) + 9;
		else if ((x>=930) && (x<944)) y = 0.0001*(x-930)*(x-930)*(x-930) - 0.0011*(x-930)*(x-930) + 0.075*(x-930) + 10;
		else if ((x>=944) && (x<955)) y = 0.0015*(x-944)*(x-944) + 0.08*(x-944) + 11;
		else if (x > 955) y = irsInfinty;
		else {
			y = 0.1;
		}
		
		return y;
	}
	
	public static void main(String[] args) {
		System.out.println(irse2cm(826));
	}

}

/*
 * 1.0 595 1.5 672 2.0 748 2.5 808 3.0 854 3.5 887 4.0 912 4.5 929 5.0 943 5.5
 * 954 6.0 962 6.5 969 7.0 977 7.5 981.5 8.0 986 8.5 990 9.0 992 9.5 995 10 997
 * 10.5 999
 * 
 * 
 * 
 * 
 * 675 1.5 750 2 800 2.5 847 3 884 3.5 915 4 932 4.5 947 5 957 5.5 965 6 972 6.5
 * 977 7 980 7.5 986 8 990 8.5 992 9 997 10 999 10.5
 */

/*
 * x aus [1.5; 2] S0(x) = -53.3107(x-1.5)^3 + 163.3277(x-1.5) + 675 =
 * -53.3107x^3 + 239.898x^2 - 196.5194x + 609.932 x aus [2; 2.5] S1(x) =
 * 66.5534(x-2)^3 - 79.966(x-2)^2 + 123.3447(x-2) + 750 = 66.5534x^3 -
 * 479.2862x^2 + 1241.849x - 348.9803 x aus [2.5; 3] S2(x) = -36.9028(x-2.5)^3 +
 * 19.864(x-2.5)^2 + 93.2937(x-2.5) + 800 = -36.9028x^3 + 296.6349x^2 -
 * 697.9535x + 1267.5219 x aus [3; 3.5] S3(x) = 25.0577(x-3)^3 - 35.4901(x-3)^2
 * + 85.4806(x-3) + 847 = 25.0577x^3 - 261.0098x^2 + 974.9804x - 405.412 x aus
 * [3.5; 4] S4(x) = -31.3282(x-3.5)^3 + 2.0965(x-3.5)^2 + 68.7838(x-3.5) + 884 =
 * -31.3282x^3 + 331.0424x^2 - 1097.2024x + 2012.1345 x aus [4; 4.5] S5(x) =
 * 36.255(x-4)^3 - 44.8958(x-4)^2 + 47.3841(x-4) + 915 = 36.255x^3 - 479.9558x^2
 * + 2146.7907x - 2313.1895 x aus [4.5; 5] S6(x) = -17.6918(x-4.5)^3 +
 * 9.4867(x-4.5)^2 + 29.6796(x-4.5) + 932 = -17.6918x^3 + 248.3264x^2 -
 * 1130.4792x + 2602.7152 x aus [5; 5.5] S7(x) = 10.5123(x-5)^3 - 17.051(x-5)^2
 * + 25.8974(x-5) + 947 = 10.5123x^3 - 174.7355x^2 + 984.8303x - 922.8005 x aus
 * [5.5; 6] S8(x) = -0.3574(x-5.5)^3 - 1.2826(x-5.5)^2 + 16.7306(x-5.5) + 957 =
 * -0.3574x^3 + 4.6141x^2 - 1.5927x + 885.6415 x aus [6; 6.5] S9(x) =
 * -1.0828(x-6)^3 - 1.8186(x-6)^2 + 15.18(x-6) + 965 = -1.0828x^3 + 17.6718x^2 -
 * 79.939x + 1042.3343 x aus [6.5; 7] S10(x) = -3.3114(x-6.5)^3 -
 * 3.4428(x-6.5)^2 + 12.5493(x-6.5) + 972 = -3.3114x^3 + 61.1297x^2 - 362.4152x
 * + 1654.3659 x aus [7; 7.5] S11(x) = 14.3285(x-7)^3 - 8.41(x-7)^2 +
 * 6.6229(x-7) + 977 = 14.3285x^3 - 309.3075x^2 + 2230.6448x - 4396.1073 x aus
 * [7.5; 8] S12(x) = -14.0024(x-7.5)^3 + 13.0827(x-7.5)^2 + 8.9592(x-7.5) + 980
 * = -14.0024x^3 + 328.1366x^2 - 2550.1855x + 7555.9685 x aus [8; 8.5] S13(x) =
 * 1.6811(x-8)^3 - 7.9209(x-8)^2 + 11.5402(x-8) + 986 = 1.6811x^3 - 48.2679x^2 +
 * 461.0506x - 473.9946 x aus [8.5; 9] S14(x) = 7.2779(x-8.5)^3 -
 * 5.3992(x-8.5)^2 + 4.8801(x-8.5) + 990 = 7.2779x^3 - 190.9853x^2 + 1674.1483x
 * - 3911.1047 x aus [9; 9.5] S15(x) = -6.7927(x-9)^3 + 5.5176(x-9)^2 +
 * 4.9393(x-9) + 992 = -6.7927x^3 + 188.9198x^2 - 1744.9979x + 6346.334 x aus
 * [9.5; 10] S16(x) = 3.8928(x-9.5)^3 - 4.6714(x-9.5)^2 + 5.3625(x-9.5) + 995 =
 * 3.8928x^3 - 115.6164x^2 + 1148.0965x - 2815.1318 x aus [10; 10.5] S17(x) =
 * -0.7786(x-10)^3 + 1.1678(x-10)^2 + 3.6107(x-10) + 997 = -0.7786x^3 +
 * 24.5247x^2 - 253.3147x + 1856.2389
 */

/*
 * x aus [675; 750] S0(x) = 0.00557(x-675) + 1.5  
 * x aus [750; 800] S1(x) = 0.00004(x-750)^2 + 0.00885(x-750) + 2
 * x aus [800; 847] S2(x) = -0.00002(x-800)^2 + 0.01011(x-800) + 2.5 
 * x aus [847; 884] S3(x) = 0.00007(x-847)^2 + 0.01258(x-847) + 3 
 * x aus [884; 915] S4(x) = 0.00001(x-884)^3 - 0.00007(x-884)^2 +
 * 0.01273(x-884) + 3.5 = 0.00001x^3 - 0.01524x^2 + 13.54468x - 4012.77984 x aus
 * [915; 932] S5(x) = -0.00001(x-915)^3 + 0.00046(x-915)^2 + 0.02503(x-915) + 4
 * = -0.00001x^3 + 0.03383x^2 - 31.35418x + 9681.37398 x aus [932; 947] S6(x) =
 * 0.00002(x-932)^3 - 0.00016(x-932)^2 + 0.03028(x-932) + 4.5 = 0.00002x^3 -
 * 0.06705x^2 + 62.66781x - 19528.12597 x aus [947; 957] S7(x) =
 * -0.00001(x-947)^3 + 0.00092(x-947)^2 + 0.04177(x-947) + 5 = -0.00001x^3 +
 * 0.02877x^2 - 28.07636x + 9116.78374 x aus [957; 965] S8(x) = 0.00063(x-957)^2
 * + 0.05725(x-957) + 5.5 = -0.00975x^2 + 8.79055x - 2643.7608 x aus [965; 972]
 * S9(x) = -0.00003(x-965)^3 + 0.00071(x-965)^2 + 0.06798(x-965) + 6 =
 * -0.00003x^3 + 0.09221x^2 - 89.59891x + 29004.84961 x aus [972; 977] S10(x) =
 * 0.00106(x-972)^3 + 0.00005(x-972)^2 + 0.07333(x-972) + 6.5 = 0.00106x^3 -
 * 3.08159x^2 + 2995.3261x - 970510.85244 x aus [977; 980] S11(x) =
 * -0.00379(x-977)^3 + 0.0159(x-977)^2 + 0.15309(x-977) + 7 = -0.00379x^3 +
 * 11.13138x^2 - 10890.73885x + 3551717.63311 x aus [980; 986] S12(x) =
 * 0.00129(x-980)^3 - 0.01823(x-980)^2 + 0.14611(x-980) + 7.5 = 0.00129x^3 -
 * 3.82372x^2 + 3765.25243x - 1235906.18451 x aus [986; 990] S13(x) =
 * 0.00235(x-986)^3 + 0.00507(x-986)^2 + 0.06715(x-986) + 8 = 0.00235x^3 -
 * 6.94017x^2 + 6838.07758x - 2245841.38552 x aus [990; 992] S14(x) =
 * -0.00923(x-990)^3 + 0.03325(x-990)^2 + 0.22041(x-990) + 8.5 = -0.00923x^3 +
 * 27.4342x^2 - 27192.54858x + 8984265.24856 x aus [992; 997] S15(x) =
 * 0.00271(x-992)^3 - 0.02211(x-992)^2 + 0.24268(x-992) + 9 = 0.00271x^3 -
 * 8.10119x^2 + 8058.55178x - 2672098.60481 x aus [997; 999] S16(x) =
 * -0.0031(x-997)^3 + 0.01861(x-997)^2 + 0.22519(x-997) + 10 = -0.0031x^3 +
 * 9.29611x^2 - 9286.54966x + 3092256.774
 */